<html>
<head>
<#assign basePath=request.contextPath>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>后台管理系统</title>
    <link href="${basePath}/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/css/font-awesome.min.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/css/form.lzy.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/css/good.lzy.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css"
          rel="stylesheet">
    <style>
        #page-wrapper h1 {
            display: block;
            margin-bottom: 20px;
            border-bottom: 1px solid #999;
            font-size: 16px;
            padding-left: 2px;
            font-weight: bold;
            line-height: 35px;
        }

        select.year, select.mouth {
            width: 100px;
        }

        #btn {
            display: inline-block;
            background-color: #ffbe34;
            line-height: 35px;
            padding: 0 15px;
            font-size: 14px;
            color: #fff;
            border-radius: 4px;
            cursor: pointer;
        }

        #depart-box {
            display: block;
            padding: 20px;
        }

        #depart-box label {
            display: inline-block;
            margin: 20px 20px 0;
        }

        #depart-box .bot {
            display: block;
            padding-top: 50px;
            text-align: center;
        }

        #fileValue {
            opacity: 0;
            width: 0px;
            height: 0px;
            font-size: 0px;
        }

        #file {
            display: inline-block;
        }

        .check-box, .identity-box {
            display: none;
        }

        .text {
            display: block;
        }
        .span-text{margin-left: 30px;}
        #fileValue{ width: 0; height: 0; opacity: 0; font-size: 0;}

        .coupon-item,.cashback-item {padding-left:20px; padding-bottom:10px; margin-bottom: 10px; position: relative;}
        .coupon-item .coupon-number,.cashback-item .cashback-number {position:absolute; top:8px; left:0;font-size: 16px; border:1px solid #999; display: inline-block; width:30px; height: 30px;
            border-radius:100%; line-height: 30px; text-align: center;}
        .coupon-item .form-group,.cashback-item .form-group {margin-top:0px;}
        .coupon-add-wrap .coupon-add,.cashback-add-wrap .cashback-add {display: inline-block; width:30px; height: 30px; line-height:30px; text-align: center; border-radius:100%;
            background: #00B83F;font-size: 30px; color:#fff; vertical-align: middle; cursor:pointer;}
        .coupon-remove,.cashback-remove {display: inline-block; width:30px; height: 30px; line-height:32px; text-align: center; border-radius:100%;
            background: #999;font-size: 18px; color:#fff; vertical-align: middle; cursor:pointer;position:absolute; top:56px; right:20px;}
        .cashback-remove {top:26px;}
        .coupon-item:first-child .coupon-remove,.cashback-item:first-child .cashback-remove {display: none;}
        img.obj-img {vertical-align: bottom;}
    </style>
</head>
<body>

<div class="panel panel-lzy">
    <div class="panel-body">
        <h5 class="tips-lzy">操作提示</h5>
        <ul class="tips-list-lzy">
            <li><span>◆&nbsp;<span>标识“<font color="red">*</font>”的选项为必填项，其余为选填项。</span></span></li>
        </ul>
    </div>
</div>

<div id="page-wrapper">
    <div class="panel panel-f5">
        <div class="panel-body row">
            <input type="hidden" id="_ctx" value="${basePath}"/>
            <form id="Form" class="form-horizontal" method="post">
                <input type="hidden" id="id" name="id" <#if dto??>value="${dto.id!}"</#if>/>
                <h1>● 创建卡券套餐类型</h1>
                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4  detail-span"><span class="text-red">*</span>&nbsp;套餐名称：</span>
                    <div class="col-sm-9 col-xs-8">
                        <input type="text" class="form-control" size="16" name="name" maxlength="30"  placeholder="请填写套餐名称" <#if dto??>value="${dto.name!}"</#if>><span class="text-warning"> 注：请填写套餐名称,便于运营管理套餐</span>
                    </div>
                </div>

                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4  detail-span">&nbsp;<span class="text-red">*</span>&nbsp;上传套餐封面：</span>
                    <div class="col-sm-9 col-xs-8">
                        <!--新增图片-->
                    <#if (dto.cover)??>
                        <input class="obj-input" id="cover" name="cover" value="${dto.cover!}" type="text">
                        <img class="obj-img" src="${dto.cover!}" width="100" height="100">
                        <span class="input-file-edit">
                                 <input type="file" data-action="goods" data-image="banner" onchange="uploadImg(this)">
                            </span>
                    <#else>
                        <input class="obj-input" id="cover" name="cover" value="" type="text">
                        <img class="obj-img" src="" style="display:none" width="100" height="100">
                        <span class="input-file">
                                <input type="file" data-action="goods" data-image="banner" onchange="uploadImg(this)">
                            </span>
                    </#if>
                        <span class="text-warning">请根据运营需要上传套餐封面图，格式：png,bmp.jpg。</span>
                    </div>
                </div>


                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4  detail-span"><span class="text-red">*</span>&nbsp;卡券套餐总价：</span>
                    <div class="col-sm-9 col-xs-8">
                    <#if  dto??>
                        <input type="text" class="form-control coupon-name-num" name="price" maxlength="11"  placeholder="" id="couponSumMoney" <#if dto??>value="${(dto.price)?c}"</#if>> 元 <span class="text-warning"> &nbsp;&nbsp;注：总价由所有的卡券的金额累加起来</span>
                    <#else>
                        <input type="text" class="form-control coupon-name-num" name="price" maxlength="11"  placeholder="" id="couponSumMoney" value="0"> 元 <span class="text-warning"> &nbsp;&nbsp;注：总价由所有的卡券的金额累加起来</span>
                    </#if>
                    </div>
                </div>
            <#if  dto??>
                <div class="clearfix" style="margin:20px  0  15px;">
                    <span class="control-label col-sm-2 col-xs-4  detail-span"><span class="text-red">*</span>&nbsp;设置卡券：</span>
                <div class="col-sm-9 col-xs-8 coupon-item-wrap">
                    <#if (dto.projectList)??>
                        <#list dto.projectList as project>

                            <div class="coupon-item">
                                <span class="coupon-number"> ${project_index+1} </span>
                                <span class="coupon-remove"> &times; </span>
                                <div class="form-group">
                                    <span class="control-label col-sm-2 col-xs-4  detail-span">卡券类型：</span>
                                    <div class="col-sm-9 col-xs-8">
                                        <select class="form-control coupon-name-type" name="projectList[${project_index}].projectId">
                                            <#if (couponPriceList)??>
                                                <#list couponPriceList as couponPrice>
                                                    <option value="${couponPrice.couponId!}"   <#if project.projectId  == couponPrice.couponId>selected = "selected"</#if>   >${couponPrice.name!}</option>
                                                </#list>
                                            </#if>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <span class="control-label col-sm-2 col-xs-4  detail-span">卡券单价：</span>
                                    <div class="col-sm-9 col-xs-8">
                                        <select class="form-control coupon-name-price" name="projectList[${project_index}].price">
                                            <#if (couponPriceList)??>
                                                <#list couponPriceList as couponPrice>
                                                    <#list couponPrice.priceList as price>
                                                        <option data-id="${couponPrice.couponId!}"  value="${price?c}" <#if project.price  == price>selected = "selected"</#if>>${price?c}</option>
                                                    </#list>
                                                </#list>
                                            </#if>
                                        </select>元
                                        <span class="text-warning">&nbsp;&nbsp;注：请选择卡券的单价，设置卡券数量之后，将会显示总价</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <span class="control-label col-sm-2 col-xs-4  detail-span">卡券张数：</span>
                                    <div class="col-sm-9 col-xs-8">
                                        <#if (dto.project)></#if>
                                        <input type="number" class="form-control coupon-name-num" min="1" name="projectList[${project_index}].containNum"  placeholder="请输入卡券套餐的张数" value="${project.containNum!}">张
                                        <span class="text-warning">&nbsp;&nbsp;注：1张起步</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <span class="control-label col-sm-2 col-xs-4  detail-span">有效期：</span>
                                    <div class="col-sm-9 col-xs-8">
                                        <input type="number" class="form-control coupon-name-time" min="1" name="projectList[${project_index}].validTime"  placeholder="请输入卡券有效天数" value="${project.validTime!}">天
                                    </div>
                                </div>
                            </div>

                        </#list>
                        <div class="coupon-add-wrap"><span class="coupon-add"> + </span>&nbsp;&nbsp;新增卡券类型</div>
                    </div>
                    </#if>
                </div>
            <#else>
                <div class="clearfix" style="margin:20px  0  15px;">
                    <span class="control-label col-sm-2 col-xs-4  detail-span"><span class="text-red">*</span>&nbsp;设置卡券：</span>
                    <div class="col-sm-9 col-xs-8 coupon-item-wrap">
                        <div class="coupon-item">
                            <span class="coupon-number"> 1 </span>
                            <span class="coupon-remove"> &times; </span>
                            <div class="form-group">
                                <span class="control-label col-sm-2 col-xs-4  detail-span">卡券类型：</span>
                                <div class="col-sm-9 col-xs-8">
                                    <select class="form-control coupon-name-type" name="projectList[0].projectId">
                                        <#if (couponPriceList)??>
                                            <#list couponPriceList as couponPrice>
                                                <option value="${couponPrice.couponId!}">${couponPrice.name!}</option>
                                            </#list>
                                        </#if>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <span class="control-label col-sm-2 col-xs-4  detail-span">卡券单价：</span>
                                <div class="col-sm-9 col-xs-8">
                                    <select class="form-control coupon-name-price" name="projectList[0].price">
                                        <#if (couponPriceList)??>
                                            <#list couponPriceList as couponPrice>
                                                <#list couponPrice.priceList as price>
                                                    <option data-id="${couponPrice.couponId!}"  value="${price?c}">${price?c}</option>
                                                </#list>
                                            </#list>
                                        </#if>
                                    </select>元
                                    <span class="text-warning">&nbsp;&nbsp;注：请选择卡券的单价，设置卡券数量之后，将会显示总价</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <span class="control-label col-sm-2 col-xs-4  detail-span">卡券张数：</span>
                                <div class="col-sm-9 col-xs-8">
                                    <#if (dto.project)></#if>
                                    <input type="number"  class="form-control coupon-name-num" min="1" name="projectList[0].containNum"  placeholder="请输入卡券套餐的张数" value="">张
                                    <span class="text-warning">&nbsp;&nbsp;注：1张起步</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <span class="control-label col-sm-2 col-xs-4  detail-span">有效期：</span>
                                <div class="col-sm-9 col-xs-8">
                                    <input type="number" class="form-control coupon-name-time" min="1" name="projectList[0].validTime"  placeholder="请输入卡券有效天数" value="">天
                                </div>
                            </div>
                        </div>
                        <div class="coupon-add-wrap"><span class="coupon-add"> + </span>&nbsp;&nbsp;新增卡券类型</div>

                    </div>
                </div>
            </#if>
                <h1>● 其他设置</h1>
                <div class="clearfix" style="margin:20px  0  15px;">
                    <span class="control-label col-sm-2 col-xs-4  detail-span"><span class="text-red">*</span>&nbsp;设置收益比：</span>
                    <div class="col-sm-9 col-xs-8 cashback-item-wrap">
                    <#if dto??>
                        <#if (dto.yieldRatioDtoList)??>
                            <#list dto.yieldRatioDtoList as yieldRatio>
                                <div class="cashback-item">
                                    <span class="cashback-number"> ${yieldRatio_index+1} </span>
                                    <span class="cashback-remove"> &times; </span>
                                    <div class="form-group">
                                        <span class="control-label col-sm-2 col-xs-4  detail-span">返现时间：</span>
                                        <div class="col-sm-9 col-xs-8">
                                            <select class="form-control cashback-name-time" name="yieldRatioDtoList[${yieldRatio_index}].cashbackTime" id="">
                                                <option value="1" <#if yieldRatio.cashbackTime  == 1>selected = "selected"</#if> >1个月</option>
                                                <option value="6" <#if yieldRatio.cashbackTime  == 6>selected = "selected"</#if>>6个月</option>
                                                <option value="12" <#if yieldRatio.cashbackTime  == 12>selected = "selected"</#if>>12个月</option>
                                                <option value="24" <#if yieldRatio.cashbackTime  == 24>selected = "selected"</#if>>2 年</option>
                                                <option value="36" <#if yieldRatio.cashbackTime  == 36>selected = "selected"</#if>>3 年</option>
                                                <option value="48" <#if yieldRatio.cashbackTime  == 48>selected = "selected"</#if>>4 年</option>
                                                <option value="60" <#if yieldRatio.cashbackTime  == 60>selected = "selected"</#if>>5 年</option>
                                            </select>
                                            <span class="text-warning">请选择收益时效日期</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <span class="control-label col-sm-2 col-xs-4  detail-span">返现比：</span>
                                        <div class="col-sm-9 col-xs-8">
                                            <input type="text" class="form-control cashback-name-rate" style="width:100px" name="yieldRatioDtoList[${yieldRatio_index}].cashbackRatio"  placeholder="输入收益比" value="${yieldRatio.cashbackRatio!}">%
                                            <span class="text-warning">&nbsp;&nbsp;注：请输入收益比例</span>
                                        </div>
                                    </div>
                                </div>
                            </#list>
                        </#if>
                    <#else>
                        <div class="cashback-item">
                            <span class="cashback-number"> 1 </span>
                            <span class="cashback-remove"> &times; </span>
                            <div class="form-group">
                                <span class="control-label col-sm-2 col-xs-4  detail-span">返现时间：</span>
                                <div class="col-sm-9 col-xs-8">
                                    <select class="form-control cashback-name-time" name="yieldRatioDtoList[0].cashbackTime" id="">
                                        <option value="1">1个月</option>
                                        <option value="6">6个月</option>
                                        <option value="12">12个月</option>
                                        <option value="24">2 年</option>
                                        <option value="36">3 年</option>
                                        <option value="48">4 年</option>
                                        <option value="60">5 年</option>
                                    </select>
                                    <span class="text-warning">请选择收益时效日期</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <span class="control-label col-sm-2 col-xs-4  detail-span">返现比：</span>
                                <div class="col-sm-9 col-xs-8">
                                    <input type="text" class="form-control cashback-name-rate" style="width:100px" name="yieldRatioDtoList[0].cashbackRatio"  placeholder="输入收益比" value="">%
                                    <span class="text-warning">&nbsp;&nbsp;注：请输入收益比例</span>
                                </div>
                            </div>
                        </div>
                    </#if>
                        <div class="cashback-add-wrap"><span class="cashback-add"> + </span>&nbsp;&nbsp;新增收益比</div>
                    </div>
                </div>


                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4  detail-span"><span class="text-red">*</span>&nbsp;设置限制提现期限：</span>
                    <div class="col-sm-9 col-xs-8">
                        <input type="text" class="form-control" size="16" name="limitTime"  placeholder="输入天数" <#if dto??>value="${dto.limitTime!}"</#if>>天
                    </div>
                </div>

                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4  detail-span">商家分利设置：</span>
                    <div class="col-sm-9 col-xs-8">
                        <input type="text" class="form-control" size="16" name="benefit" <#if dto??>value="${dto.benefit!}"</#if>>%
                        <span class="text-warning"> &nbsp;&nbsp;&nbsp;专属于购买套餐的用户，在套餐券买完之后，帮助龙之游销售券时的分利</span>
                    </div>
                </div>

                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4  detail-span">分利拨比设置：</span>
                    <div class="col-sm-9 col-xs-8">
                        <input type="text" class="form-control" size="16" name="profit" <#if dto??>value="${dto.profit!}"</#if>>%
                        <span class="text-warning"> &nbsp;&nbsp;&nbsp;专属于业务员推销套餐时，公司内部的分利</span>
                    </div>
                </div>

                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4 detail-span"><span class="text-red">*</span>&nbsp;上传合同文档：</span>
                    <div class="col-sm-9 col-xs-8">
                    <#if (dto.office)??>
                        <input type="text" id="fileText" class="form-control" size="50" value="${dto.office!}" readonly />
                        <input type="file" data-action="office" data-image="word" onchange="uploadFile(this,'.docx',10)" id="file">
                        <input type="text" id="fileValue" name="office" value="${dto.office!}">
                    <#else>
                        <input type="text" id="fileText" class="form-control" size="50" value="" readonly style="display: none" />
                        <input type="file" data-action="office" data-image="word" onchange="uploadFile(this,'.docx',10)" id="file">
                        <input type="text" id="fileValue" name="office" value="" class="file">
                    </#if>
                        <span class="text-warning text">请上传不超过10MB*.docx格式的标准文档</span>
                    </div>
                </div>

                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4  detail-span">&nbsp;<span class="text-red">*</span>&nbsp;上传分享标签图：</span>
                    <div class="col-sm-9 col-xs-8">
                    <#if (dto.labelDiagram)??>
                        <input class="obj-input" id="cover" name="labelDiagram" value="${dto.labelDiagram!}" type="text">
                        <img class="obj-img" src="${dto.labelDiagram!}" width="100" height="100">
                        <span class="input-file-edit">
                                <input type="file" data-action="goods" data-image="banner" onchange="uploadImg(this)">
                            </span>
                    <#else>
                        <!--新增图片-->
                        <input class="obj-input" id="cover" name="labelDiagram" value="${dto.labelDiagram!}" type="text">
                        <img class="obj-img" src="" style="display:none" width="100" height="100">
                        <span class="input-file">
                                <input type="file" data-action="goods" data-image="banner" onchange="uploadImg(this)">
                            </span>
                    </#if>
                        <span class="text-warning">注：请上传分享标签的图片，尺寸100px*100px，大小不大于3M，格式使用jpg、png、bmp</span>
                    </div>
                </div>

                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4  detail-span"><span class="text-red">*</span>&nbsp;分享标题：</span>
                    <div class="col-sm-9 col-xs-8">
                        <input type="text" class="form-control" size="58" name="title" <#if dto??>value="${dto.title!}"</#if>><br/>
                        <span class="text-warning"> 注：请填写分享标签的标题，请用最短的文字描述您想对用户说的话；（字数限制20字，之后用...表示）</span>
                    </div>
                </div>
                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4  detail-span"><span class="text-red">*</span>&nbsp;标签内容：</span>
                    <div class="col-sm-9 col-xs-8">
                        <textarea data-id="0" type="text" class="form-control" rows="2" cols="60" name="tagContent"><#if dto??>${dto.tagContent!}</#if></textarea>
                        <span class="text-warning"> 注：请填写分享标签的内容，请用简介语言描述这块标签分享的内容；（字数限制40字，之后用...表示）</span>
                    </div>
                </div>

                <div class="hr-ccc"></div>
                <div class="form-group">
                    <span class="control-label col-sm-4 col-xs-4"></span>
                    <div class="col-sm-8 col-xs-8">
                    <#if dto??>
                        <button type="button" class="btn btn-success" onclick="submitFormEdit();"><i
                                class="fa fa-check"></i>提交
                        </button>
                    <#else>
                        <button type="button" class="btn btn-success" onclick="submitForm();"><i
                                class="fa fa-check"></i> 提交
                        </button>
                    </#if>
                        <button type="button" class="btn btn-info" onclick="goBack()"><i class="fa fa-close"></i>返回
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="clone-htmlcode" style="display: none;">
    <!-- 新增卡券类型-->
    <div class="coupon-item">
        <span class="coupon-number"> 1 </span>
        <span class="coupon-remove"> &times; </span>
        <div class="form-group">
            <span class="control-label col-sm-2 col-xs-4  detail-span">卡券类型：</span>
            <div class="col-sm-9 col-xs-8">
                <select class="form-control coupon-name-type" name="projectList[0].projectId">
                <#if (couponPriceList)??>
                    <#list couponPriceList as couponPrice>
                        <option value="${couponPrice.couponId!}">${couponPrice.name!}</option>
                    </#list>
                </#if>
                </select>
            </div>
        </div>
        <div class="form-group">
            <span class="control-label col-sm-2 col-xs-4  detail-span">卡券单价：</span>
            <div class="col-sm-9 col-xs-8">
                <select class="form-control coupon-name-price" name="projectList[0].price">
                <#if (couponPriceList)??>
                    <#list couponPriceList as couponPrice>
                        <#list couponPrice.priceList as price>
                            <option data-id="${couponPrice.couponId!}"  value="${price?c}">${price?c}</option>
                        </#list>
                    </#list>
                </#if>
                </select>元
                <span class="text-warning">&nbsp;&nbsp;注：请选择卡券的单价，设置卡券数量之后，将会显示总价</span>
            </div>
        </div>
        <div class="form-group">
            <span class="control-label col-sm-2 col-xs-4  detail-span">卡券张数：</span>
            <div class="col-sm-9 col-xs-8">
            <#if (dto.project)></#if>
                <input type="number"  class="form-control coupon-name-num" min="1" name="projectList[0].containNum"  placeholder="请输入卡券套餐的张数" value="">张
                <span class="text-warning">&nbsp;&nbsp;注：1张起步</span>
            </div>
        </div>
        <div class="form-group">
            <span class="control-label col-sm-2 col-xs-4  detail-span">有效期：</span>
            <div class="col-sm-9 col-xs-8">
                <input type="number" class="form-control coupon-name-time" min="1" name="projectList[0].validTime"  placeholder="请输入卡券有效天数" value="">天
            </div>
        </div>
    </div>
    <!-- 新增收益比 -->
    <div class="cashback-item">
        <span class="cashback-number"> 1 </span>
        <span class="cashback-remove"> &times; </span>
        <div class="form-group">
            <span class="control-label col-sm-2 col-xs-4  detail-span">返现时间：</span>
            <div class="col-sm-9 col-xs-8">
                <select class="form-control cashback-name-time" name="yieldRatioDtoList[0].cashbackTime" id="">
                    <option value="1">1个月</option>
                    <option value="6">6个月</option>
                    <option value="12">12个月</option>
                    <option value="24">2 年</option>
                    <option value="36">3 年</option>
                    <option value="48">4 年</option>
                    <option value="60">5 年</option>
                </select>
                <span class="text-warning">请选择收益时效日期</span>
            </div>
        </div>
        <div class="form-group">
            <span class="control-label col-sm-2 col-xs-4  detail-span">返现比：</span>
            <div class="col-sm-9 col-xs-8">
                <input type="text" class="form-control cashback-name-rate" style="width:100px" name="yieldRatioDtoList[0].cashbackRatio"  placeholder="输入收益比" value="">%
                <span class="text-warning">&nbsp;&nbsp;注：请输入收益比例</span>
            </div>
        </div>
    </div>
</div>



<script src="${basePath}/bootstrap/js/jquery.js" type="text/javascript"></script>
<script src="${basePath}/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="${basePath}/bootstrap/plugin/layer/layer.js" type="text/javascript"></script>
<script type="text/javascript"
        src="https://cdn.bootcss.com/bootstrap-validator/0.5.3/js/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/bootstrap-validator/0.5.3/js/language/zh_CN.js"></script>
<script type="text/javascript">
    $(window).bootstrapValidator || document.write('<script src="${basePath}/bootstrap/js/bootstrapValidator.min.js"><\/script>' +
            '<script src="${basePath}/bootstrap/js/bootstrapValidator-zh_CN.js"><\/script>');
</script>
<script src="${basePath}/bootstrap/js/common.js" type="text/javascript"></script>
<script type="text/javascript"
        src="${basePath}/bootstrap/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript"
        src="${basePath}/bootstrap/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${basePath}/bootstrap/js/campsite.js" type="text/javascript"></script>
<script>

    function goBack() {
        window.location.href = "${basePath}/admin/coupon"
    }
    $(function () {


        /*新增卡券类型*/
        $('.coupon-item-wrap .coupon-add').click(function () {

            //var str = $('.coupon-item:first-child').clone();
            var str = $('.clone-htmlcode .coupon-item').clone();

            console.log(str);

            $('.coupon-add-wrap').before(str);

            $(this).parent().prev().find('.coupon-name-num').val('');

            $('.coupon-item-wrap .coupon-item').each(function (index,item) {
                $(this).find('.coupon-number').html((index+1));
                $(this).find('.coupon-name-type').attr('name','projectList['+index+'].projectId');
                $(this).find('.coupon-name-price').attr('name','projectList['+index+'].price');
                $(this).find('.coupon-name-num').attr('name','projectList['+index+'].containNum');
                $(this).find('.coupon-name-time').attr('name','projectList['+index+'].validTime');
            });

            var L =  $('.coupon-item-wrap .coupon-item').length;
            for(var i=0;i<L;i++){
//                $("#Form").bootstrapValidator('removeField','projectList['+i+'].containNum');
//                $("#Form").bootstrapValidator('removeField','projectList['+i+'].validTime');
//                $('#Form').data("bootstrapValidator").validateField('projectList[0].containNum').updateStatus("projectList[0].containNum",  "NOT_VALIDATED",  null );
//                $('#Form').data("bootstrapValidator").validateField('projectList[0].validTime').updateStatus("projectList[0].validTime",  "NOT_VALIDATED",  null );

                $("#Form").bootstrapValidator('addField','projectList['+i+'].containNum',{
                    validators: {
                        notEmpty: {
                            message: '请输入张数'
                        },
                        regexp: {
                            regexp: regInt,
                            message: '请输入整数'
                        }
                    }
                });
                $("#Form").bootstrapValidator('addField','projectList['+i+'].validTime',{
                    validators: {
                        notEmpty: {
                            message: '请输入天数'
                        },
                        regexp: {
                            regexp: regInt,
                            message: '请输入整数'
                        }
                    }
                })
            }
        });

        /*删除卡券类型*/
        $('.coupon-item-wrap').on('click','.coupon-remove',function () {
            var _this =this;
            console.log(111);
            layer.confirm('确定要删除吗？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $(_this).parent().remove();

                $('.coupon-item-wrap .coupon-item').each(function (index,item) {
                    $(this).find('.coupon-number').html((index+1));
                    $(this).find('.coupon-name-type').attr('name','projectList['+index+'].projectId');
                    $(this).find('.coupon-name-price').attr('name','projectList['+index+'].price');
                    $(this).find('.coupon-name-num').attr('name','projectList['+index+'].containNum');
                    $(this).find('.coupon-name-time').attr('name','projectList['+index+'].validTime');
                });
                couponSumMoney();
                layer.closeAll();
            }, function(){
                layer.closeAll();
            });
        });
        /*填写张数  失去焦点 触发计算*/
        $('.coupon-item-wrap').on('blur','.coupon-name-num',function () {
            couponSumMoney();
        });
        /*选择单价 触发计算*/
        $('.coupon-item-wrap').on('change','.coupon-name-price',function () {
            couponSumMoney();
        });
        $('.coupon-item').each(function(index,ele){
            var val = $(this).find('.coupon-name-type').val();
            $(this).find('.coupon-name-price option').each(function (index,ele) {
                if($(this).attr('data-id') == val){
                    $(this).show();
                }else{
                    $(this).hide();
                }
            });
        });

        $('.coupon-item-wrap').on('change','.coupon-name-type',function () {
            var val = $(this).val();
            console.log(val);
            $(this).parents('.coupon-item').find('.coupon-name-price option').each(function (index,ele) {
                if($(this).attr('data-id') == val){
                    $(this).show();
                }else{
                    $(this).hide();
                }
            });

//            console.log($(this).find('option[data-id='+val+']:first'));
//            console.log($(this).find('option[data-id='+val+']:first').text());
//            console.log($(this).find('option[data-id='+val+']').eq(1));
//            console.log($(this).parents('.coupon-item').find('.coupon-name-price option[data-id='+val+']').eq(0).text());
            var optionValue = $(this).parents('.coupon-item').find('.coupon-name-price option[data-id='+val+']').eq(0).text();
            $(this).parents('.coupon-item').find('.coupon-name-price').val(optionValue);
        });

        /*计算总金额*/
        function couponSumMoney() {
            var sunMoney = 0;
            $('.coupon-item-wrap .coupon-item').each(function (index,item) {
                var price = $(this).find('.coupon-name-price').val();
                var number =$(this).find('.coupon-name-num').val();
                if(!isNaN(price) && !isNaN(number)){
                    sunMoney += price*number;
                }
            });
            $('#couponSumMoney').val(sunMoney).blur();
        }

        /*新增收益比*/
        $('.cashback-item-wrap .cashback-add').click(function () {
            //$('.cashback-add-wrap').before($('.cashback-item:first-child').clone());
            var str = $('.clone-htmlcode .cashback-item').clone();
            $('.cashback-add-wrap').before(str);

            $(this).parent().prev().find('.cashback-name-rate').val('');

            $('.cashback-item-wrap .cashback-item').each(function (index,item) {
                $(this).find('.cashback-number').html((index+1));
                $(this).find('.cashback-name-time').attr('name','yieldRatioDtoList['+index+'].cashbackTime');
                $(this).find('.cashback-name-rate').attr('name','yieldRatioDtoList['+index+'].cashbackRatio');
            })

            var L =  $('.cashback-item-wrap .cashback-item').length;
            for(var i=0;i<L;i++){
                $("#Form").bootstrapValidator('addField','yieldRatioDtoList['+i+'].cashbackRatio',{
                    validators: {
                        notEmpty: {
                            message: '请输入收益比例'
                        },
                        regexp: {
                            regexp: regPrice,
                            message: '请输入整数或小数(最多保留两位小数)'
                        },
                        callback:{
                            message:'请输入不大于100的数',
                            callback:function (value) {
                                if(value>100){
                                    return false;
                                }else{
                                    return true;
                                }
                            }
                        }
                    }
                });
            }
        });

        /*删除收益比*/
        $('.cashback-item-wrap').on('click','.cashback-remove',function () {
            var _this =this;
            console.log(111);
            layer.confirm('确定要删除吗？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $(_this).parent().remove();
                $('.cashback-item-wrap .cashback-item').each(function (index,item) {
                    $(this).find('.cashback-number').html((index+1));
                    $(this).find('.cashback-name-time').attr('name','yieldRatioDtoList['+index+'].cashbackTime');
                    $(this).find('.cashback-name-rate').attr('name','yieldRatioDtoList['+index+'].cashbackRatio');
                })
                layer.closeAll();
            }, function(){
                layer.closeAll();
            });
        });
    });
    //判断数组是否有重复
    function isRepeat(arr){
        var json = {};
        for(var i = 0; i < arr.length; i++){
            if(json[arr[i]]){
                return true;
            }
            json[arr[i]] = true;
        }
        return false;
    }



    //新增
    function submitForm() {
        var bsVal = $("#Form").data('bootstrapValidator');
        bsVal.validate();
        if (bsVal.isValid()) {
            var cashbackTimeArr = [];
            $('.cashback-item-wrap .cashback-name-time').each(function (index,item) {
                cashbackTimeArr.push($(this).val());
            });
            var cashbackYes =  isRepeat(cashbackTimeArr);
            if(cashbackYes){
                alert('抱歉，“设置收益比”的“返现时间”重复，请删除重复的选项!')
            }else{
                $.ajax({
                    type: 'POST',
                    dataType: 'json',
                    url: '${basePath}/admin/coupon/save',
                    data: $("#Form").serialize(),
                    success: function (data) {
                        if (data.code == '0') {
                            layer.alert('操作成功', {
                                icon: 1
                            }, function () {
                                window.location.href = '${basePath}/admin/coupon';
                            })
                        } else {
                            layer.alert(data.desc, {
                                icon: 5
                            });
                        }
                    },
                    error: function () {
                        layer.alert('系统错误', {
                            icon: 5
                        });
                    }
                });
            }




        }
        else {
            var smallTop = $("small:visible").eq(0).offset().top - 50;
            $("html,body").animate({scrollTop: smallTop}, 300);
        }
    }

    //编辑
    function submitFormEdit() {

        if (!$("#identity-input").is(":checked")) {
            $("#identityId").val("0")
        }

        var bsVal = $("#Form").data('bootstrapValidator');
        bsVal.validate();
        if (bsVal.isValid()) {

            var cashbackTimeArr = [];
            $('.cashback-item-wrap .cashback-name-time').each(function (index,item) {
                cashbackTimeArr.push($(this).val());
            });
            var cashbackYes =  isRepeat(cashbackTimeArr);
            if(cashbackYes){
                alert('抱歉，“设置收益比”的“返现时间”重复，请删除重复的选项!')
            }else{
                $.ajax({
                    type: 'POST',
                    dataType: 'json',
                    url: '${basePath}/admin/coupon/update',
                    data: $("#Form").serialize(),
                    success: function (data) {
                        if (data.code == '0') {
                            layer.alert('操作成功', {
                                icon: 1
                            }, function () {
                                window.location.href = '${basePath}/admin/coupon';
                            })
                        } else {
                            layer.alert(data.desc, {
                                icon: 5
                            });
                        }
                    },
                    error: function () {
                        layer.alert('系统错误', {
                            icon: 5
                        });
                    }
                });
            }


        }
        else {
            var smallTop = $("small:visible").eq(0).offset().top - 50;
            $("html,body").animate({scrollTop: smallTop}, 300);
        }
    }

    //表单验证
    $('#Form').bootstrapValidator({
        fields: {
            name: {
                validators: {
                    notEmpty: {
                        message: '请输入套餐名称'
                    }
                }
            },
            cover: {
                trigger: "change",
                validators: {
                    notEmpty: {
                        message: '请上传套餐封面'
                    }
                }
            },
            price: {
                trigger: "input blur",
                validators: {
                    notEmpty: {
                        message: '卡券套餐总价不能为空'
                    },
                    regexp: {
                        regexp: regPrice,
                        message: '请输入整数或小数(最多保留两位小数)'
                    }
                }
            },
            office: {
                trigger: "change",
                validators: {
                    notEmpty: {
                        message: '请上传文档'
                    }
                }
            },
            limitTime: {
                validators: {
                    notEmpty: {
                        message: '限制提现期限'
                    },
                    regexp: {
                        regexp: regInt,
                        message: '请输入整数'
                    }
                }
            },
            'projectList[0].containNum': {
                validators: {
                    notEmpty: {
                        message: '请输入张数'
                    },
                    regexp: {
                        regexp: regInt,
                        message: '请输入整数'
                    }
                }
            },
            'projectList[0].validTime': {
                validators: {
                    notEmpty: {
                        message: '请输入天数'
                    },
                    regexp: {
                        regexp: regInt,
                        message: '请输入整数'
                    }
                }
            },
            'yieldRatioDtoList[0].cashbackRatio': {
                validators: {
                    notEmpty: {
                        message: '请输入收益比例'
                    },
                    regexp: {
                        regexp: regPrice,
                        message: '请输入整数或小数(最多保留两位小数)'
                    },
                    callback:{
                        message:'请输入不大于100的数',
                        callback:function (value) {
                            if(value>100){
                                return false;
                            }else{
                                return true;
                            }
                        }
                    }
                }
            },
            labelDiagram: {
                trigger: "change",
                validators: {
                    notEmpty: {
                        message: '请上传分享标签图'
                    }
                }
            },
            title: {
                validators: {
                    notEmpty: {
                        message: '请输入套餐名称'
                    }
                }
            },
            tagContent: {
                validators: {
                    notEmpty: {
                        message: '请输入套餐名称'
                    }
                }
            },
            benefit:{
                validators: {
                    regexp: {
                        regexp: regPrice,
                        message: '请输入整数或小数(最多保留两位小数)'
                    },
                    callback:{
                        message:'请输入不大于100的数',
                        callback:function (value) {
                            if(value>100){
                                return false;
                            }else{
                                return true;
                            }
                        }
                    }
                }
            },
            profit:{
                validators: {
                    regexp: {
                        regexp: regPrice,
                        message: '请输入整数或小数(最多保留两位小数)'
                    },
                    callback:{
                        message:'请输入不大于100的数',
                        callback:function (value) {
                            if(value>100){
                                return false;
                            }else{
                                return true;
                            }
                        }
                    }
                }
            }
        }
    });
</script>
</body>
</html>